﻿package cn.valorin.command;

import java.util.HashSet;
import java.util.Set;

import org.bukkit.Bukkit;

import cn.valorin.command.sub.AdminHelp;
import cn.valorin.command.sub.Changelang;
import cn.valorin.command.sub.CreatingTable;
import cn.valorin.command.sub.PlayerHelp;
import cn.valorin.command.sub.Reload;
import cn.valorin.command.sub.WaterMachine;

public class CommandsHandler {

    private Set<SubCommand> commands = new HashSet<>();

    public CommandsHandler(String name) {
    	commands.add(new AdminHelp());
    	commands.add(new PlayerHelp());
    	commands.add(new Changelang());
    	commands.add(new Reload());
    	commands.add(new WaterMachine());
    	commands.add(new CreatingTable());
        Bukkit.getPluginCommand(name).setExecutor(new CommandsExecutor());
    }

    public SubCommand getSubCommand(String cmd) {
        for (SubCommand command : commands) {
          if (command.getName() != null)//无简称
          {
            if (command.getName().equalsIgnoreCase(cmd)) {
              return command;
            }
          } else {//有简称
        	if (command.getFullName().equalsIgnoreCase(cmd) || command.getAbbreviation().equalsIgnoreCase(cmd)) {
              return command;
            }
          }
        }
        return null;
    }

    public Set<SubCommand> getCommands() {
        return commands;
    }
}
